// API统一管理
// 引入二次封装的axios
import requests from './requests'
import mockRequest from './requestsMock'

// 三级联动接口
// requests是axios的二次封装，它发送请求的返回结果是Promise对象
export const reqCategoryList = () => requests({
  // 请求地址与请求方式
  url: '/product/getBaseCategoryList',
  method: 'get'
})

// 请求mock banner数据
export const reqGetBannerList = () => mockRequest({
  url: '/banner',
  method: 'get'
})

// 请求mock floor数据
export const reqFloorList = () => mockRequest({
  url: '/floor',
  method: 'get'
})

// 请求Search数据
export const reqGetSearchInfo = (params) => requests({
  url: '/list',
  method: 'POST',
  // params是要传递的参数对象
  data: params
})

// 请求Detail产品信息数据
export const reqGoodsInfo = (skuId) => requests({
  url: `/item/${skuId}`,
  method: 'GET',
})

// 将产品添加到购物车（或者更新购物车中产品信息）
export const reqAddOrUpdateShopCart = (skuId, skuNum) => requests({
  url: `cart/addToCart/${skuId}/${skuNum}`,
  method: 'POST'
})

// 获取购物车里的产品列表
export const reqCartList = () => requests({
  url: '/cart/cartList',
  method: 'GET'
})

// 删除购物车里的产品
export const reqDeleteCart = (skuId) => requests({
  url: `/cart/deleteCart/${skuId}`,
  method: 'DELETE'
})

// 切换商品选中状态
export const reqUpdateChecked = (skuId, isChecked) => requests({
  url: `/cart/checkCart/${skuId}/${isChecked}`,
  method: 'GET'
})

// 获取验证码
export const reqCode = (phone) => requests({
  url: `/user/passport/sendCode/${phone}`,
  method: 'GET'
})

// 用户注册
export const reqUserRegister = (data) => requests({
  url: '/user/passport/register',
  method: 'POST',
  data
})

// 用户登陆
export const reqLogin = (data) => requests({
  url: '/user/passport/login',
  method: 'POST',
  // 这里的data传入的是对象，里面包含用户名和密码
  data
})

// 获取用户登陆信息【带着token】
export const reqUserInfo = () => requests({
  url: '/user/passport/auth/getUserInfo',
  method: 'GET'
})

// 退出登陆
export const reqLogout = () => requests({
  url: '/user/passport/logout',
  method: 'GET'
})

// 获取用户地址信息
export const reqUserAddress = () => requests({
  url: '/user/userAddress/auth/findUserAddressList',
  method: 'GET'
})

// 获取订单交易页信息
export const reqTrade = () => requests({
  url: '/order/auth/trade',
  method: 'GET'
})

// 提交订单
export const reqSubmitOrder = (tradeNo, data) => requests({
  url: '/order/auth/submitOrder',
  method: 'POST',
  // 订单编号
  params: {
    tradeNo
  },
  data
})

// 获取订单支付信息
export const reqPayment = (orderId) => requests({
  url: `/payment/weixin/createNative/${orderId}`,
  method: 'GET'
})

// 查询订单支付状态
export const reqPayStatus = (orderId) => requests({
  url: `/payment/weixin/queryPayStatus/${orderId}`,
  method: 'GET'
})

// 获取订单列表
export const reqOrderList = (page, limit) => requests({
  url: `/order/auth/${page}/${limit}`,
  method: 'GET'
})
